    result = await db.execute(query)
    courses = result.scalars().all()
    
    # 如果指定了周次，过滤课程
    if week:
        filtered_courses = []
        for course in courses:
            weeks_info = course.weeks
            # 确保 weeks_info 是一个有效的字典
            if isinstance(weeks_info, dict):
                start = weeks_info.get("start")
                end = weeks_info.get("end")
                pattern = weeks_info.get("pattern")

                # 检查周次是否在范围内
                if start is not None and end is not None and start <= week <= end:
                    # 根据模式（every, odd, even）判断
                    if pattern == "every":
                        filtered_courses.append(course)
                    elif pattern == "odd" and week % 2 != 0:
                        filtered_courses.append(course)
                    elif pattern == "even" and week % 2 == 0:
                        filtered_courses.append(course)
        courses = filtered_courses
    
    # 构建响应数据
    class_info = {
        "class_code": class_obj.class_code,
        "class_name": class_obj.class_name,
        "college_name": class_obj.college_name
    }
